import {$host} from "./index";
import LoginUserDto from "../utils/dto/auth/loginUserDto";

/** Логин юзера
 * @param dto - LoginUserDto дто для логина юзера*/
export const login = async (dto: LoginUserDto) => {
    const response = await $host.post("api/Auth/Login", dto)
    if (response.status === 200) {
        const cookies = response.headers['set-cookie'];
        if (cookies) {
            cookies.forEach((cookie: string) => {
                document.cookie = cookie;
            });
        }
    } else {
        console.error(response.status, response.statusText);
    }
    
    return response;
}

/** Выход юзера*/
export const logout = async () => {
    return await $host.delete("api/Auth/Logout")
}

